import { defHttp } from '/@/common/util/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/emp/hubTeamResultQuota/getPage',
  save='/emp/hubTeamResultQuota/add',
  edit='/emp/hubTeamResultQuota/edit',
  deleteOne = '/emp/hubTeamResultQuota/delete',
  deleteBatch = '/emp/hubTeamResultQuota/deleteBatch',
  importExcel = '/emp/hubTeamResultQuota/importExcel',
  exportXls = '/emp/hubTeamResultQuota/exportXls',
  batchUpdate = '/emp/hubTeamResultQuota/updateBatch', //批量新增
  header = '/emp/dynamicTable/getQuotaFactorOrgHeader', //动态表头
  getPeriodTree = '/emp/epmBasePeriod/periodTree', //考核周期树
  init = '/emp/hubTeamResultQuota/init', // 初始化
}

export let PeriodTree = [];
export const getPeriodTree = () => {
  const params = {
    type: 'yearM',
  };
  return new Promise((resolve) => {
    defHttp.post({ url: Api.getPeriodTree, params }, { joinParamsToUrl: true }).then((res) => {
      PeriodTree = res;
      resolve(res);
    });
  });
};
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 批量更新
 * @param params
 */
export const updateList = (params) => {
  let url = Api.batchUpdate;
  return defHttp.post({ url: url, params });
};


/**
 * description: 查询动态表头
 * @params: @
 */
export const getColumn = (params) => defHttp.post({ url: Api.header, params });

export const init = (params) => defHttp.post({ url: Api.init, params });